Traditionally, IDE's may provide a source code analyzer, or may include the ability to utilize an external (e.g., to plug in) an external source code analyzer. Traditional source code analyzers may analyze the initialization of instance variables within source code.
Instance variables explicitly initialized, in source code, to their default values are, in many cases, redundant, as the Java Language Specification guarantees that each instance variable is set to its appropriate default initial value, when it is created. Explicitly assigning an instance variable, in source code, with its default initial value is quite a common pattern, albeit unnecessary.
Existing source code analyzers may attempt to identify redundant assignments. However, in many cases the level of analysis provided by these source code analyzers may be very basic. In certain situations traditional source code analyzers may incorrectly identify assignments of default values as being redundant when they are not.
For example, a traditional source code analyzer may issue incorrect warnings when the following simple example pseudocode is analyzed.
public class RedundInit {{x = 6;}int x = 0; // this assignment is not redundantpublic static void main(String[ ] args) {RedundInit r = new RedundInit( );System.out.println(r.x);}}
A traditional, existing, source code analyzer, such as Intellij IDEA™, may issue a redundant field initialization and recommend removing the initialization of variable ‘x’ to ‘0’. However, if the initialization is removed the program will then output an incorrect result (e.g., the program would print ‘6’, rather than ‘0’).